REVIEW a) a. if (v < 0) q = Math.sqrt(15); b. if (count % 10 == 0) h = 3; c. i = (x > 0) ? 7 : 8; b) if (pH < 7) { neutral = 0; base = 0; acid = 1; } else if (pH > 7) { neutral = 0; base = 1; acid = 0; } else { neutral = 1; base = 0; acid = 0; } ---------------------------------------------------------------------------------------- 1) switch(response) { case 'y': System.out.print("Your request is being processed"); break; case 'n': System.out.print("Thank you anyway for your consideration"); break; case 'h': System.out.print("Sorry, no help is currently available"); break; default: System.out.print("Invalid entry; please try again"); break; } System.out.println(); 2) switch(status) { case 200: System.out.print("OK (fulfilled)"); break; case 403: System.out.print("forbidden"); break; case 404: System.out.print("not found"); break; case 500: System.out.print("server error"); break; } 3) import java.util.Scanner; public class Question5 { public static void main(String[] args) { //create Scanner obj Scanner sc = new Scanner(System.in); //prompt for input System.out.print("Input a month number: "); //validate input for month if (!sc.hasNextInt()) { System.out.println("Invalid! Enter a whole number."); } else { int monthNum = sc.nextInt(); //read in month //prompt for input System.out.print("Input a year: "); //validate input for year if (!sc.hasNextInt()) { System.out.println("Invalid! Enter a whole number."); } else { int year = sc.nextInt(); //read in year //initialize String to default N/A String month = "N/A"; //initialize days to default 0 int days = 0; //determine number of days in month switch (monthNum){ case 1, 3, 5, 7, 8, 10, 12 -> { days = 31; //all these months have 31 days if(monthNum == 1) month = "January"; else if (monthNum == 3) month = "March"; else if (monthNum == 5) month = "May"; else if (monthNum == 7) month = "July"; else if (monthNum == 8) month = "August"; else if (monthNum == 10) month = "October"; else if (monthNum == 12) month = "December"; } case 4, 6, 9, 11 -> { days = 30; //all these months have 30 days if(monthNum == 4) month = "April"; else if (monthNum == 6) month = "June"; else if (monthNum == 9) month = "September"; else if (monthNum == 11) month = "November"; } case 2 -> { month = "February"; //leap year if divisible by 4 AND NOT 100 OR divisible by 400 (AND 100) if((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0)){ days = 29; } else { days = 28; } } default -> System.out.println("Invalid entry. Not a month"); } System.out.printf("%s %d has %d days%n", month, year, days); } } } } 4) import java.util.Scanner; public class VoterEligibility { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter your age : "); int age = input.nextInt(); int res = (age >= 18) ? 1 : 0; switch (res) { case 0: System.out.println("Sorry, you are not eligible to vote."); break; case 1: System.out.printf("Congratulations! You are eligible to vote!"); break; } } } ---------------------------------------------------------------------------------------- LAB 2 DISCUSSED IN CLASS ----------------------------------------------------------------------------------------